﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 对数组的操作
{
    class Program
    {
        static void Main(string[] args)
        {
            int maxnum = int.MinValue;
            int minnum = int.MaxValue;
            int average = 0;
            int summary = 0;
            int num = 0;

                //从键盘读入一行数据，生成数组
                Console.WriteLine("请输入一串整数，用空格分开：");
                string str = Console.ReadLine();
                string[] Array1 = str.Split(' ');
                int[] Array2 = new int[Array1.Length];
                bool d = true;
                for (int i = 0; i < Array1.Length; i++)
                {
                    int c;
                    if (!int.TryParse(Array1[i], out c))
                    {
                        d = false;
                        break;
                    }
                    else
                    {
                        Array2[i] = c;
                    }
                    if (d == false)
                    {
                        Console.WriteLine("输入数字违法！");
                        continue;
                    }
                }

         
            
            //数组操作
            ArrayOperator(ref maxnum,ref minnum,ref average,ref summary,ref Array2);

            Console.WriteLine("最大值为:" + maxnum + ", 最小值为：" + minnum + ", 平均值为：" + average + ",总和为：" + summary);
            Console.ReadLine();
        }
            


        static public void ArrayOperator(ref int maxm,ref int min, ref int ave,ref int sum,ref int[] Array)
        {
            foreach(int i in Array)
            {
                if (maxm < i)
                {
                    maxm = i;
                }
                

                if (min > i)
                {
                    min = i;
                }
                

                sum += i;
            }
            int length = Array.Length;
            ave = sum / length;
        }

        


    }
}
